<html>
<head><meta charset="utf-8"><title>Poor LLVM IR generation · t-compiler · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/index.html">t-compiler</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html">Poor LLVM IR generation</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="206238700"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206238700" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206238700">(Aug 07 2020 at 09:32)</a>:</h4>
<p>The LLVM IR generated for a trivial <code>drop_in_place</code> function looks like this in a release build:</p>



<a name="206238706"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206238706" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206238706">(Aug 07 2020 at 09:32)</a>:</h4>
<div class="codehilite"><pre><span></span><code>; core::ptr::drop_in_place::&lt;std::thread::local::AccessError&gt;
; Function Attrs: nonlazybind uwtable
define internal void @_RINvNtCseeAmXa5bjUx_4core3ptr13drop_in_placeNtNtNtCsbHjphw8CCgR_3std6thread5l
ocal11AccessErrorECs3LJk5zYATtk_5cargo(%&quot;std::thread::local::AccessError&quot;* %_1) unnamed_addr #1 {
start:
  %0 = alloca {}, align 1
  ret void
}
</code></pre></div>



<a name="206238739"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206238739" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206238739">(Aug 07 2020 at 09:33)</a>:</h4>
<p>And for a debug build:</p>
<div class="codehilite"><pre><span></span><code>; core::ptr::drop_in_place::&lt;std::thread::local::AccessError&gt;
; Function Attrs: nonlazybind uwtable
define internal void @_RINvNtCseeAmXa5bjUx_4core3ptr13drop_in_placeNtNtNtCsbHjphw8CCgR_3std6thread5l
ocal11AccessErrorECsjWOLik5knP7_5cargo(%&quot;std::thread::local::AccessError&quot;* %_1) unnamed_addr #0 !dbg
 !204877 {
start:
  %_1.dbg.spill = alloca %&quot;std::thread::local::AccessError&quot;*, align 8
  %0 = alloca {}, align 1
  store %&quot;std::thread::local::AccessError&quot;* %_1, %&quot;std::thread::local::AccessError&quot;** %_1.dbg.spill,
 align 8
  call void @llvm.dbg.declare(metadata %&quot;std::thread::local::AccessError&quot;** %_1.dbg.spill, metadata
!204882, metadata !DIExpression()), !dbg !204885
  ret void, !dbg !204885
}
</code></pre></div>



<a name="206238842"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206238842" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206238842">(Aug 07 2020 at 09:34)</a>:</h4>
<p>My LLVM-fu is weak, but that appears to allocate some small or zero-sized on the stack, and then immediately return</p>



<a name="206238877"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206238877" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206238877">(Aug 07 2020 at 09:35)</a>:</h4>
<p>Would it be possible to just not generate these functions?</p>



<a name="206239001"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206239001" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206239001">(Aug 07 2020 at 09:37)</a>:</h4>
<p>There are a lot of them, e.g. often 100s in a large crate</p>



<a name="206239022"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206239022" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206239022">(Aug 07 2020 at 09:37)</a>:</h4>
<p>A similar case, this time for <code>drop</code>:</p>



<a name="206239027"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206239027" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206239027">(Aug 07 2020 at 09:37)</a>:</h4>
<div class="codehilite"><pre><span></span><code>; core::mem::drop::&lt;u8&gt;
; Function Attrs: inlinehint nonlazybind uwtable
define internal void @_RINvNtCseeAmXa5bjUx_4core3mem4drophECs3LJk5zYATtk_5cargo(i8 %_x) unnamed_addr
 #0 {
start:
  br label %bb1

bb1:                                              ; preds = %start
  ret void
}
</code></pre></div>



<a name="206239423"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206239423" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206239423">(Aug 07 2020 at 09:44)</a>:</h4>
<p><code>drop_in_place</code> is often the single function contributing most of the LLVM IR lines. I was planning to look into the MIR shim generation to see if there's an easy fix for that.</p>



<a name="206239585"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206239585" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206239585">(Aug 07 2020 at 09:46)</a>:</h4>
<p>Seems like some "don't generate it if it's trivial, don't call it if it's trivial" logic could be useful?</p>



<a name="206239728"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206239728" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206239728">(Aug 07 2020 at 09:48)</a>:</h4>
<p>You need the trivial drop glue for trait objects, but last time I checked the code trivial drop glue should at least already be shared between types. Maybe that logic doesn't work though.</p>



<a name="206239815"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206239815" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206239815">(Aug 07 2020 at 09:50)</a>:</h4>
<p>In the <code>cargo</code> crate, this exact pattern appears at the end of 5265 functions</p>
<div class="codehilite"><pre><span></span><code>  br label %bb1

bb1:                                              ; preds = %start
  ret void
}
</code></pre></div>



<a name="206239924"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206239924" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206239924">(Aug 07 2020 at 09:51)</a>:</h4>
<p>skimming through them, there are no other branches to the label, i.e. it's unnecessary</p>



<a name="206239935"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206239935" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206239935">(Aug 07 2020 at 09:51)</a>:</h4>
<p>codegen might create a dedicated return block to point all <code>Return</code> terminators to. I think I've read that LLVM deals better with a single <code>ret</code> instruction in the function. Could be wrong though.</p>



<a name="206239995"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206239995" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206239995">(Aug 07 2020 at 09:52)</a>:</h4>
<p>These are all really simple functions without any need for branches</p>



<a name="206240039"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206240039" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206240039">(Aug 07 2020 at 09:53)</a>:</h4>
<p>Ah, if there's only one branch to it then yeah, seems unnecesary</p>



<a name="206240129"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206240129" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206240129">(Aug 07 2020 at 09:54)</a>:</h4>
<p>I'm seeing it with non-void returns, too. Lots of funcs like this:</p>



<a name="206240144"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206240144" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206240144">(Aug 07 2020 at 09:54)</a>:</h4>
<div class="codehilite"><pre><span></span><code>; core::mem::needs_drop::&lt;(cargo::core::source::source_id::SourceId, alloc::string::String)&gt;
; Function Attrs: inlinehint nonlazybind uwtable
define internal zeroext i1 @_RINvNtCseeAmXa5bjUx_4core3mem10needs_dropTNtNtNtNtCs3LJk5zYATtk_5cargo4
core6source9source_id8SourceIdNtNtCsdfan3MWuEp4_5alloc6string6StringEEBM_() unnamed_addr #0 {
start:
  %0 = alloca i8, align 1
  call void @llvm.lifetime.start.p0i8(i64 1, i8* %0)
  store i8 1, i8* %0, align 1
  %1 = load i8, i8* %0, align 1, !range !3
  %2 = trunc i8 %1 to i1
  call void @llvm.lifetime.end.p0i8(i64 1, i8* %0)
  br label %bb1

bb1:                                              ; preds = %start
  ret i1 %2
}
</code></pre></div>



<a name="206240323"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206240323" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206240323">(Aug 07 2020 at 09:56)</a>:</h4>
<p>Another interesting one:</p>
<div class="codehilite"><pre><span></span><code>; core::mem::take::&lt;core::option::Option&lt;alloc::rc::Rc&lt;(alloc::string::String, cargo::core::resolver
::types::RcList&lt;alloc::string::String&gt;)&gt;&gt;&gt;
; Function Attrs: inlinehint nonlazybind uwtable
define internal i64* @_RINvNtCseeAmXa5bjUx_4core3mem4takeINtNtB4_6option6OptionINtNtCsdfan3MWuEp4_5a
lloc2rc2RcTNtNtBX_6string6StringINtNtNtNtCs3LJk5zYATtk_5cargo4core8resolver5types6RcListB1o_EEEEEB1S
_(i64** align 8 dereferenceable(8) %dest) unnamed_addr #0 {
start:
; call &lt;core::option::Option&lt;alloc::rc::Rc&lt;(alloc::string::String, cargo::core::resolver::types::RcL
ist&lt;alloc::string::String&gt;)&gt;&gt; as core::default::Default&gt;::default
  %_3 = call i64* @_RNvXs9_NtCseeAmXa5bjUx_4core6optionINtB5_6OptionINtNtCsdfan3MWuEp4_5alloc2rc2RcT
NtNtBP_6string6StringINtNtNtNtCs3LJk5zYATtk_5cargo4core8resolver5types6RcListB1g_EEEENtNtB7_7default
7Default7defaultB1K_()
  br label %bb1

bb1:                                              ; preds = %start
; call core::mem::replace::&lt;core::option::Option&lt;alloc::rc::Rc&lt;(alloc::string::String, cargo::core::
resolver::types::RcList&lt;alloc::string::String&gt;)&gt;&gt;&gt;
  %0 = call i64* @_RINvNtCseeAmXa5bjUx_4core3mem7replaceINtNtB4_6option6OptionINtNtCsdfan3MWuEp4_5al
loc2rc2RcTNtNtB10_6string6StringINtNtNtNtCs3LJk5zYATtk_5cargo4core8resolver5types6RcListB1r_EEEEEB1W
_(i64** align 8 dereferenceable(8) %dest, i64* %_3)
  br label %bb2

bb2:                                              ; preds = %bb1
  ret i64* %0
}
</code></pre></div>



<a name="206240335"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206240335" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206240335">(Aug 07 2020 at 09:56)</a>:</h4>
<p>That has two unnecessary branches to two unnecessary labels</p>



<a name="206240390"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206240390" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206240390">(Aug 07 2020 at 09:57)</a>:</h4>
<p>skimming through this file, I haven't yet found a branch that was necessary(!)</p>



<a name="206240480"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206240480" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206240480">(Aug 07 2020 at 09:59)</a>:</h4>
<p>Lots of functions with three unnecessary branches to three unnecessary labels</p>



<a name="206240591"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206240591" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206240591">(Aug 07 2020 at 10:00)</a>:</h4>
<p>in debug builds there are debug annotations associated with these branches and labels, e.g.:</p>
<div class="codehilite"><pre><span></span><code>  br label %bb1, !dbg !363425

bb1:                                              ; preds = %start
  ret i64* %0, !dbg !363426
}
</code></pre></div>



<a name="206240606"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206240606" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206240606">(Aug 07 2020 at 10:00)</a>:</h4>
<p>Not sure if they are important, but might explain why they're present</p>



<a name="206240926"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206240926" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> bjorn3 <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206240926">(Aug 07 2020 at 10:05)</a>:</h4>
<p>There is already code to prevent an unnecessary jump from the function prelude to the start mir block in case there is no jump from any mir block to the start block (aka the start mir block has no predecessors). Something similar could be done for the return block when there is exactly one predecessor.</p>



<a name="206241171"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206241171" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206241171">(Aug 07 2020 at 10:09)</a>:</h4>
<p>Why does that code use <code>call</code> instead of <code>invoke</code>? Is <code>-Cpanic=abort</code> in that example <span class="user-mention" data-user-id="120989">@njn</span>?</p>



<a name="206241229"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206241229" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206241229">(Aug 07 2020 at 10:10)</a>:</h4>
<p>Sorry, I just turned that computer off for the weekend</p>



<a name="206241251"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206241251" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206241251">(Aug 07 2020 at 10:10)</a>:</h4>
<p>Reasonable</p>



<a name="206241271"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206241271" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206241271">(Aug 07 2020 at 10:10)</a>:</h4>
<p><span class="user-mention" data-user-id="133247">@bjorn3</span> It's not just the return block, as shown by the example above with <code>bb2</code></p>



<a name="206241986"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206241986" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206241986">(Aug 07 2020 at 10:21)</a>:</h4>
<p>The "bb" labels suggest that every basic block is getting its own label, and we always branch from one basic block to the next even when it's not necessary, or something like that</p>



<a name="206242344"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206242344" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206242344">(Aug 07 2020 at 10:26)</a>:</h4>
<p>If i could interject quickly: currently mir only generates a single return block (except for the generator transform which can insert more) but there is an optmization being worked on that would push returns up into predecessors (see issue: <a href="https://github.com/rust-lang/rust/issues/72022">https://github.com/rust-lang/rust/issues/72022</a>, opt: <a href="https://github.com/rust-lang/rust/pull/74839">https://github.com/rust-lang/rust/pull/74839</a>)</p>



<a name="206243011"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206243011" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206243011">(Aug 07 2020 at 10:37)</a>:</h4>
<p>That seems quite different. I'm complaining about small functions with straight-line code having one or more obviously unnecessary <code>br label %bbN / bbN:</code> pairs...</p>



<a name="206245050"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206245050" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206245050">(Aug 07 2020 at 11:08)</a>:</h4>
<p>it seems like this would be handled by this optimization (or really SimplifyCfg) or are you talking about this occuring purely in debug builds?</p>



<a name="206245136"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206245136" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Xavier Denis <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206245136">(Aug 07 2020 at 11:10)</a>:</h4>
<p>the existence of the block for return is probably just naive codegen especially since previously there oculd only be a single return for the whole function</p>



<a name="206245664"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206245664" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> njn <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206245664">(Aug 07 2020 at 11:17)</a>:</h4>
<p>Maybe they could be handled by this optimization, but "move returns up to previous blocks" sounds different to "remove unnecessary branch/label pairs".  And as I said before: it's not just the return block, as shown by the example above with bb2</p>



<a name="206245765"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/131828-t-compiler/topic/Poor%20LLVM%20IR%20generation/near/206245765" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> Jonas Schievink  [he/him] <a href="https://rust-lang.github.io/zulip_archive/stream/131828-t-compiler/topic/Poor.20LLVM.20IR.20generation.html#206245765">(Aug 07 2020 at 11:19)</a>:</h4>
<p>that might just happen with <code>-Cpanic=abort</code>, otherwise codegen should be using <code>invoke</code> instead of <code>call</code>, which is a terminator and <em>requires</em> the next block to exist</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>